  //保存企业信息
  function updateQyxx(id){
    var qyxxForm = document.forms["qyxxForm"];
     var url='${ctx}/yw-rq-qyjyxkgd!doUpdate.action'
     var qyxxForm=serializeForm(qyxxForm);
     var wait=waitWin();
     var qyxxForm=Ext.encode(qyxxForm);
     wait.show();
       Ext.Ajax.request({
       url: url,
       dataType:"json",
       params: qyxxForm,
       success:function(response){
        wait.hide();
         var result=response.responseText;
         if(result=="success"){
              Ext.Msg.alert("提示","操作成功",function(){
            	window.location.reload();
            });
         }else{
            Ext.Msg.alert("提示","操作失败");
              return;    
         }
       
    },failure: function() {
        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
         wait.hide();
     } 
    
    });
        
  	}
  	
  	
  	
  	  //液化燃气保存企业信息
  function updateQyInfo(id){
    var qyxxForm = document.forms["qyxxForm"];
     var url='${ctx}/yw-rq-qyjyxkpz!doUpdate.action'
     var qyxxForm=serializeForm(qyxxForm);
     var wait=waitWin();
     var qyxxForm=Ext.encode(qyxxForm);
     wait.show();
       Ext.Ajax.request({
       url: url,
       dataType:"json",
       params: qyxxForm,
       success:function(response){
        wait.hide();
         var result=response.responseText;
         if(result=="success"){
              Ext.Msg.alert("提示","操作成功",function(){
                window.location.reload();
            });
         }else{
            Ext.Msg.alert("提示","操作失败");
              return;    
         }
       
    },failure: function() {
        Ext.Msg.alert('错误', '请求失败,请稍后重试'); 
         wait.hide();
     } 
    
    });
        
    }
    
  	
  	//编辑企业信息
  	function editQyxx(ajid){
      Ext.Ajax.request({
       url: '${ctx}/yw-rq-qyjyxkgd!toUpdate.action',
       success:editHandler,
       failure:faultHandler,
       params: {id:ajid}
    });

}
function faultHandler()
{
    alert("数据加载错误!");
}  

//设施一览表
function resultSslyb(result){
    var jsonData=Ext.decode(result.responseText);
    var array=null;
    var finalData=null;
    for(var key in jsonData){
           if(key=="ssylb"){
             array=jsonData[key];
           }else if(key=="finalDatas"){
             finalData=jsonData[key]
           }
     }  
	var html='<table width="1000" border="0" cellspacing="2" cellpadding="2">'+
	'<tr>'+
	'<td><table width="100%" border="0" cellspacing="2" cellpadding="2" >'+
	'<tr><td height="55" bordercolor="#000000" align="center" style="font-size:22px;">'+
	'<br/><b>修改后企业燃气设施一览表</b> <br/> <br/>'+
	'</td></tr>'+
	'</table></td>'+
	'</tr>'+
	'<tr>'+
	'<td>'+
	'<table id="t_ssylb" width="100%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="2" class="tpl_list_ui" id="myTable">'+
	'<tbody id="myBody">'+
	'<tr>'+
	'<td width="5%" height="0" ></td>'+
	'<td width="15%"></td>'+
	'<td width="25%"></td>'+
	'<td width="18%"></td>'+
	'<td width="20%"></td>'+
	'</tr>'+
	'<TR d="myTr0" align="center">'+
	'<td height="25" align="center" bordercolor="#000000">序号</td>'+
	'<td heght="25" align="center" colspan="2" bordercolor="#000000">名称</td>'+
	'<td height="25" align="center" colspan="2" bordercolor="#000000">地址</td>'+
	'<td height="25" align="center" bordercolor="#000000">设施类别</td>'+
	'<td height="25" align="center" bordercolor="#000000">操作</td>'+
	'</tr>';
    for(var i=0;i<array.length;i++){
        html+="<tr height='25' align='center'><td>"+(i+1)+
        "</td><td colspan='2'>"+array[i].ssmc+
        "</td><td colspan='2'>"+array[i].ssaddress+
        "</td><td>"+array[i].sslb+
        "</td><td><input type='button' value='编辑'  onclick='toSsylb("+array[i].ssylbid+")'> <input type='button' value='删除'  onclick='deletessylb("+array[i].ssylbid+")'></td></tr>";
   
	    }
	    html+='</tbody></table></td></tr>'+
	    '<tr><td colspan="5" bordercolor="#000000"><input type="button" value="添加一行" onclick="tosaveSsLyb()"> <input type="button" value="删除全部" onclick="deleteAll()"></td>'+
	    '</tr>'+
	    '</table>';
	    document.getElementById("ssDiv").innerHTML=html;
  
    var finalhtml='<table width="1000" border="0" cellspacing="2" cellpadding="2">'+
               '<tr>'+
			    '<td><table width="100%" border="0" cellspacing="2" cellpadding="2" >'+
			    '<tr><td height="55" bordercolor="#000000" align="center" style="font-size:22px;">'+
			    '<br/><b>原企业燃气设施一览表</b> <br/> <br/>'+
			    '</td></tr>'+
			    '</table></td>'+
			    '</tr>'+
			    '<tr>'+
			    '<td>'+
			    '<table id="t_ssylb" width="100%" border="1" bordercolor="#000000" cellspacing="0" cellpadding="2" class="tpl_list_ui" id="myTable">'+
			    '<tbody id="myBody">'+
			    '<tr>'+
			    '<td width="5%" height="0" ></td>'+
			    '<td width="15%"></td>'+
			    '<td width="22%"></td>'+
			    '<td width="20%"></td>'+
			    '</tr>'+
			    '<TR d="myTr0" align="center">'+
			    '<td height="25" align="center" bordercolor="#000000">序号</td>'+
			    '<td heght="25" align="center" colspan="2" bordercolor="#000000">名称</td>'+
			    '<td height="25" align="center" colspan="2" bordercolor="#000000">地址</td>'+
			    '<td height="25" align="center" bordercolor="#000000">设施类别</td>'+
			    '</tr>';
                 for(var k=0;k<finalData.length;k++){
				        finalhtml+="<tr height='25' align='center'><td>"+(k+1)+
				        "</td><td colspan='2'>"+finalData[k].mc+
				        "</td><td colspan='2'>"+finalData[k].dz+
				        "</td><td>"+finalData[k].sslb+
				        "</td></tr>";
				   
				        }
				        finalhtml+='</tbody></table></td></tr>'+
				        '</table>';
				  document.getElementById("fianlssdiv").innerHTML=finalhtml;
}	
function waitWin(){
    var wait = new Ext.LoadMask(Ext.getBody(), {msg:"请稍后..."}); 
    return wait;
}

function deletessylb(ssylbId){
     var id=document.getElementById("id").value;
    Ext.MessageBox.confirm('警告!','您确定要删除吗?',function(btn){
    if (btn == 'yes'){
      Ext.Ajax.request({
        url: '${ctx}/yw-rq-qyjyxkgd!deleteSsylb.action',
       success:ssylbResult,
       failure:faultHandler,
       params: { ssylbid:ssylbId,
                id:id}
        });
    }
    });
}
function  deleteAll(){
    var id=document.getElementById("id").value;
    Ext.MessageBox.confirm('警告!','您确定要删除吗?',function(btn){
    if (btn == 'yes'){
      Ext.Ajax.request({
        url: '${ctx}/yw-rq-qyjyxkgd!deleteSsylbs.action',
       success:ssylbResult,
       failure:faultHandler,
       params: { id:id}
        });
    }
    });

}

//编辑
function toSsylb(ssylbid){
    var id=document.getElementById("id").value;
      Ext.Ajax.request({
       url: '${ctx}/yw-rq-qyjyxkpz!getSsylb.action',
       success:editssylb,
       failure:faultHandler,
       params: {ssylbid:ssylbid,
                id:id
        }});
  }

function editssylb(result)
{
var array = Ext.decode(result.responseText);
 _editwin=new Ext.Window({
        title:'编辑燃气设施',
        width:400,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td colspan="2"><input type="hidden" name="qyjyxkid" id="qyjyxkid" value="'+array.qyjyxkid+'">'+
        '<input type="hidden" name="filepath" id="filepath" value="'+array.filepath+'">'+
            '<input type="hidden" name="fzr" id="fzr" value="'+array.fzr+'">'+
        '<input type="hidden" name="bszsbh" id="bszsbh" value="'+array.bszsbh+'">'+
         '<input type="hidden" name="zdlb" id="zdlb" value="'+array.zdlb+'">'+
        '<input type="hidden" name="ssylbid" id="ssylbid" value="'+array.ssylbid+'"></td>'+
        '<tr><td width:200 align=right>设施名称:</td><td><input type="text" name="ssmc" id="ssmc" value="'+array.ssmc+'"></td>'+
        '<tr><td width:200 align=right>设施地址:</td><td><input type="text" name="ssaddress" id="ssaddress" value="'+array.ssmc+'"></td>'+
          '<tr><td width:200 align=right>设施类别:</td><td><input type="text" name="sslb" id="sslb" value="'+array.sslb+'"></td></tr>'+
        '</table>',
        buttons:[{text:'保 存',handler:savessylb},{text:'取 消',handler:function(){
            _editwin.hide();
        }}]
    }).show();
}

//添加设施一览表
function  savessylb(id){
    var id=dwr.util.getValue("qyjyxkid");
	var ssylbid=dwr.util.getValue('ssylbid');
	var ssmc=dwr.util.getValue('ssmc');
	var ssaddress = dwr.util.getValue('ssaddress');
	var fzr = dwr.util.getValue('fzr');
	var sslb = dwr.util.getValue('sslb');
	var zdlb = dwr.util.getValue('zdlb');
	var filepath = dwr.util.getValue('filepath');
	var bszsbh = dwr.util.getValue('bszsbh');
	if(id=="" ||id=="undefined"){
	   id=document.getElementById("id").value;
	}
	var obj;    
	 if(ssylbid==null||typeof(ssylbid) == "undefined"||ssylbid==""){
		 obj ={
		  qyjyxkid:id,
		  ssmc:ssmc,
		  ssaddress:ssaddress,
		  fzr:fzr,
		  sslb:sslb,
		   fzr:fzr,
          filepath:filepath,
		  zdlb:zdlb
		  };    
	    }else{
		 obj ={
		  id:id,
		  ssylbid:ssylbid,
		   qyjyxkid:id,
		  ssmc:ssmc,
		  ssaddress:ssaddress,
		  fzr:fzr,
		  sslb:sslb,
		  filepath:filepath,
		  zdlb:zdlb
		  };
	    }
       var params=Ext.encode(obj);
       Ext.Ajax.request({
	       url: '${ctx}/yw-rq-qyjyxkgd!saveSsylb.action',
	       success:ssylbResult,
	       failure:faultHandler,
	       params:obj
       });
	
}

function ssylbResult(){
    var id=document.getElementById("id").value;
        if(_win!=null)
           _win.close();
         if(_editwin!=null)
         _editwin.close();
       Ext.Ajax.request({
              url: '${ctx}/yw-rq-qyjyxkgd!getsslyb.action',
              success:resultSslyb,
              failure:faultHandler,
              params: { id: id}
        });
}



//显示添加
function tosaveSsLyb(){
       _win=new Ext.Window({
        title:'新增燃气设施信息',
        width:600,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td width:200 align=right>设施名称:</td><td><input type="text" name="ssmc" id="ssmc"></td>'+
        '<tr><td width:200 align=right>设施地址:</td><td><input type="text" name="ssaddress" id="ssaddress"></td>'+
        '<tr><td width:200 align=right>设施类别:</td><td><input type="text" name="sslb" id="sslb"></td></tr>'+
        '</table>',
        buttons:[{text:'保 存',handler:savessylb},{text:'取 消',handler:function(){
            _win.hide();
        }}]
    });
    _win.show();
}



function serializeForm(form) {  
    var fElements = form.elements  
            || (document.forms[form] || Ext.getDom(form)).elements, hasSubmit = false, encoder = encodeURIComponent, element, options, name, val, data = {}, type;  
    Ext.each(fElements, function(element) {  
        name = element.name;  
        type = element.type;  
        if (!element.disabled && name) {  
            if (/select-(one|multiple)/i.test(type)) {  
                Ext.each(element.options, function(opt) {  
                            if (opt.selected) {
                                data[encoder(name)] = encoder((opt.hasAttribute  
                                        ? opt.hasAttribute('value')  
                                        : opt.getAttribute('value') !== "")  
                                        ? opt.value  
                                        : opt.text);  
                            }  
                        });  
            } else if (!/file|undefined|reset|button/i.test(type)) {
           
                if (!(/radio|checkbox/i.test(type) && !element.checked)  
                        && !(type == 'submit' && hasSubmit)) {  
                        if(element.value!=""){
                          data[encoder(name)] = encoder(element.value);  
                          hasSubmit = /submit/i.test(type);  
                    }
                }  
            }  
        }  
    });  
    return data;  
} 



function editHandler(result){
var array = Ext.decode(result.responseText);
 _editwin=new Ext.Window({
        title:'编辑企业基本信息',
        width:800,
        autoHeight:true,    
        modal: true,
        labelAlign:'right',
        buttonAlign:'center',
        closeAction:'close',
        html:'<form id="qyxxForm" name="qyxxForm"><table width="700" border="0" cellspacing="2" cellpadding="2">'+
        '<tr><td colspan="4"><input type="hidden" name="id" id="id" value="'+array.id+'"></td>'+
        '<tr><td width:200 align=right>注册地址:</td><td  colspan="3" ><input type="text" size="75" maxlength="50" name="address" id="address" value="'+array.address+'"></td></tr>'+
        //'<tr><td width:200 align=right>成立时间:</td><td><input type="text" size="20"  class="textdocWdate" readonly   name="clsj" id="clsj" value="'+array.clsj+'"></td>'+
        '<td width:200 align=right>营业执照号:</td><td><input type="text" name="gszcdjh" id="gszcdjh" value="'+array.gszcdjh+'"></td></tr>'+
        '<tr><td width:200 align=right>联系人:</td><td><input type="text" name="ywlxr" id="ywlxr" value="'+array.ywlxr+'"></td>'+
        '<td width:200 align=right>联系电话:</td><td><input type="text" name="ywlxr" id="ywlxr" value="'+array.ywlxr+'"></td></tr>'+
        '<tr><td width:200 align=right>电子邮箱:</td><td><input type="text" name="dzyx" id="dzyx" value="'+array.dzyx+'"></td>'+
        '<td width:200 align=right>传真:</td><td><input type="text" name="cz" id="cz" value="'+array.cz+'"></td></tr>'+
         '<tr><td width:200 align=right>企业网址:</td><td><input type="text" name="qywz" id="qywz" value="'+array.qywz+'"></td>'+
        '<td width:200 align=right>法定代表人:</td><td><input type="text" name="fddbr" id="fddbr" value="'+array.fddbr+'"></td></tr>'+
        '<tr><td width:200 align=right>法定代表人职务:</td><td><input type="text" name="fddbrZw" id="fddbrZw" value="'+array.fddbrZw+'"></td>'+
        '<td width:200 align=right>法定代表人职称:</td><td><input type="text" name="fddbrZc" id="fddbrZc" value="'+array.fddbrZc+'"></td></tr>'+
        '<tr><td width:200 align=right>主要负责人:</td><td><input type="text" name="zyfzr" id="zyfzr" value="'+array.zyfzr+'"></td>'+
        '<td width:200 align=right>主要负责人职务:</td><td><input type="text" name="zyfzrZw" id="zyfzrZw" value="'+array.zyfzrZw+'"></td></tr>'+
        '<tr><td width:200 align=right>主要负责人职称:</td><td><input type="text" name="zyfzrZc" id="zyfzrZc" value="'+array.zyfzrZc+'"></td>'+
        '<td width:200 align=right>安全负责人:</td><td><input type="text" name="aqfzr" id="aqfzr" value="'+array.aqfzr+'"></td></tr>'+
        '<tr><td width:200 align=right>安全负责人职务:</td><td><input type="text" name="aqfzrZw" id="aqfzrZw" value="'+array.aqfzrZw+'"></td>'+
        '<td width:200 align=right>安全负责人职称:</td><td><input type="text" name="aqfzrZc" id="aqfzrZc" value="'+array.aqfzrZc+'"></td></tr>'+
         '<tr><td width:200 align=right>技术负责人:</td><td><input type="text" name="jsfzr" id="jsfzr" value="'+array.jsfzr+'"></td>'+
        '<td width:200 align=right>技术负责人职务:</td><td><input type="text" name="jsfzrZw" id="jsfzrZw" value="'+array.jsfzrZw+'"></td></tr>'+
        '<tr><td width:200 align=right>技术负责人职称:</td><td><input type="text" name="jsfzrZc" id="jsfzrZc" value="'+array.jsfzrZc+'"></td>'+
        '<td width:200 align=right>企业注册资本:</td><td><input type="text" name="qyzczb" id="qyzczb" value="'+array.qyzczb+'">（万元）</td></tr>'+
         '<tr><td width:200 align=right>企业类型:</td><td>'+
         "<input  type='radio' ${array.qylx==null ||array.qylx==1?'checked':'' } name='qylx'  value='1'  /> 国有"+　
         "<input  type='radio' ${array.qylx==null ||array.qylx==2?'checked':'' }  name='qylx' value='2' />民营"+
         "<input  type='radio' ${array.qylx==null ||array.qylx==3?'checked':'' } name='qylx'  value='3' />港澳台商投资<br/>"+
         "<input  type='radio' ${array.qylx==null ||array.qylx==4?'checked':'' }  name='qylx' value='4'  />外商投资"+
         "<input  type='radio' ${array.qylx==null ||array.qylx==5?'checked':'' } name='qylx'  value='5'  />集体"+
         "<input  type='radio' ${array.qylx==null ||array.qylx==6?'checked':'' }  name='qylx' value='6'  />中外合资(合作)</td>"+
        '<td width:200 align=right>经营范围:</td><td>'+
       "<input type='checkbox' id='jyfw1' onclick='selectjyfw(1)' name='jyfw' value='瓶装液化石油气' ${fn:indexOf(jyfw, '瓶装液化石油气') ge 0 ? 'checked' : ''}/>瓶装液化石油气<br/>"+ 
       "<input type='checkbox' id='jyfw1' onclick='selectjyfw(2)' name='jyfw'  value='瓶装液化石油气气' ${fn:indexOf(jyfw, '车用液化石油气') ge 0 ? 'checked' : ''}/>车用液化石油气"+
       "<input type='checkbox' id='jyfw1' onclick='selectjyfw(3)' name='jyfw'  value='管道燃气' ${fn:indexOf(jyfw, '管道燃气') ge 0 ? 'checked' : ''}/>管道燃气"+
       '<tr><td width:200 align=right>服务电话:</td><td><input type="text" name="qywz" id="fwdh" value="'+array.fwdh+'"></td>'+
        '<td width:200 align=right>抢险电话:</td><td><input type="text" name="qxdh" id="qxdh" value="'+array.qxdh+'"></td></tr>'+
       '<tr><td width:200 align=right>企业简介:</td><td colspan="3">'+
       "<textarea  name='qyjj' rows='7' cols='65'>"+array.qyjj+"</textarea></td>"+
        '</table></form>',
         buttons:[{text:'保 存',handler:saveQyxx},{text:'取 消',handler:function(){
            _editwin.hide();
        }}]
    }).show();
}



